package com.feidee.fd.sml.algorithm.feature

import com.feidee.fd.sml.algorithm.component.feature.{OneHotEncoder, OneHotEncoderParam}
import com.feidee.fd.sml.algorithm.util.{TestingDataGenerator, ToolClass}
import org.scalatest.FunSuite

/**
  * @Author: dongguosheng, songhaicheng
  * @Date: 2018/8/24 14:56
  */
class OneHotEncoderSuite extends FunSuite {
  val paramStr: String =
    """
      |{
      |	"inputCol": "features",
      | "outputCol": "1hot",
      |	"preserveCols": "notFeatures1,notFeatures2,notFeatures3"
      |}
    """.stripMargin

  val oneHot = new OneHotEncoder()
  val param: OneHotEncoderParam = oneHot.parseParam(new ToolClass().encrypt(paramStr))

  test("OneHotEncoder parameter construction test") {
    assert(param.input_pt == null && param.output_pt == null &&
      "features".equals(param.inputCol) && "1hot".equals(param.outputCol) &&
      "notFeatures1,notFeatures2,notFeatures3".equals(param.preserveCols) && !param.saveLast
    )
  }

  test("OneHotEncoder training function test") {
    val testingData = TestingDataGenerator.makeOrderedFeaturesData()
    new OneHotEncoder().train(param, testingData).transform(testingData).show()
  }
}
